#include "temp_humidity.h"

void setup (){
  //pinMode  (BUILTIN_LED,   OUTPUT  ) ;     // Initialize the BUILTIN_LED pin as an output
  //digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(115200);
  setup_wifi();  
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  myTicker.attach(3, tickerHandle);
  myTicker.attach(3,tempHumidityHandle);
  dht.begin();
}


void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  if(flag)
  {  
    delay(2000);
    humidity = dht.readHumidity();          // Read humidity (percent)
    temperature = dht.readTemperature();     // Read temperature as Fahrenheit
    String info;
    StaticJsonDocument<200> doc;
    doc["deviceId"] = deviceId;
    doc["temperature"] = temperature;
    doc["humidity"] = humidity;
    doc["online"] = "1";
    serializeJson(doc, info);
    client.publish("Heart",deviceId.c_str()) ;
    client.publish("Temperature_Humidity", info.c_str());
  }
}
  
